package com.itcast.googleplay.application;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import android.app.Application;
import android.content.Context;
import android.os.Handler;

public class MyApplication extends Application {
	private static Context context;
	private static Handler handler;
	private static Thread mainThread;
	private static int mainThreadId;
	//将此初始化的代码放在application的oncreate方法中,或者应用程序第一个activity的oncreate方法中
	@Override
	public void onCreate() {
		super.onCreate();
		//在此方法中需要获取handler对象,上下文环境
		context = getApplicationContext();
		//准备handler对象
		handler = new Handler();
		//hanlder应用场景(子线程往主线程中发送message)

		//获取主线程的对象,MyApplication的onCreate运行在主线程中的代码
		mainThread = Thread.currentThread();
		//获取主线程(当前线程)id方法
		mainThreadId = android.os.Process.myTid();
		
		//让ImageLoader进行初始化
		ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(context));
	}
	public static Context getContext() {
		return context;
	}
	public static Handler getHandler() {
		return handler;
	}
	public static Thread getMainThread() {
		return mainThread;
	}
	public static int getMainThreadId() {
		return mainThreadId;
	}
}
